package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Permission;
import com.design.movieticket.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "权限模块")
@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Resource
    private PermissionService permissionService;

    /** 分页查询 */
    @ApiOperation("权限信息分页展示")
    @GetMapping("/list/page")
    public Result findPermissionInfoListByPage(Permission permission, XPage<Void> page) {
        IPage<Permission> permissionInfoList = permissionService.page(XPage.toIPage(page), permissionService.buildQuery(permission));
        return new Result(permissionInfoList, ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新权限数据 */
    @ApiOperation("新增或更新权限数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditPermissionInfo(Permission permission) {
        System.out.println(" permission"+permission);
        permissionService.addOrUpdatePermissionInfo(permission);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 获取权限信息 */
    @ApiOperation("获取权限信息详情")
    @GetMapping("/getPermissionDetail/{id}")
    public Result getPermissionInfoDetail(@PathVariable long id){
        return new Result(permissionService.getPermissionDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除权限信息 */
    @ApiOperation("删除权限信息")
    @PostMapping("/delPermissionById/{id}")
    public Result delPermissionInfoById(@PathVariable long id){
        permissionService.delPermissionById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }
}
